package com.cckat.service.impl;

import com.cckat.base.BaseMapper;
import com.cckat.base.BaseServiceImpl;
import com.cckat.entity.House;
import com.cckat.entity.bo.HouseQueryBo;
import com.cckat.entity.vo.HouseVo;
import com.cckat.mapper.DictMapper;
import com.cckat.mapper.HouseMapper;
import com.cckat.service.HouseService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 静海基地
 */
@DubboService
public class HouseServiceImpl extends BaseServiceImpl<House> implements HouseService {

    @Autowired
    private HouseMapper houseMapper;

    @Autowired
    private DictMapper dictMapper;

    @Override
    public BaseMapper<House> getBaseMapper() {
        return houseMapper;
    }

    @Override
    public House getById(Long id) {
        House house = houseMapper.getById(id);
        house.setBuildStructureName(dictMapper.findNameById(house.getBuildStructureId()));
        house.setDecorationName(dictMapper.findNameById(house.getDecorationId()));
        house.setDirectionName(dictMapper.findNameById(house.getDirectionId()));
        house.setFloorName(dictMapper.findNameById(house.getFloorId()));
        house.setHouseTypeName(dictMapper.findNameById(house.getHouseTypeId()));
        house.setHouseUseName(dictMapper.findNameById(house.getHouseUseId()));
        return house;
    }


    @Override
    public void publish(Long id, Integer status) {
        House house = new House();
        house.setId(id);
        house.setStatus(status);
        houseMapper.update(house);
    }


    @Override
    public PageInfo findHouseVoPage(int pageNum, int pageSize, HouseQueryBo houseQueryBo) {
        PageHelper.startPage(pageNum, pageSize);
        Page<HouseVo> page = houseMapper.findHouseVoPage(houseQueryBo);
        for (HouseVo houseVo : page) {
            houseVo.setHouseTypeName(dictMapper.findNameById(houseVo.getHouseTypeId()));
            houseVo.setFloorName(dictMapper.findNameById(houseVo.getFloorId()));
            houseVo.setDecorationName(dictMapper.findNameById(houseVo.getDecorationId()));
        }
        return new PageInfo<>(page,10);
    }

}
